package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.JobWorkShopPost;
import com.ruoyi.system.mapper.JobWorkShopPostMapper;
import com.ruoyi.system.service.JobWorkShopPostService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 工段岗位维护(JobWorkShopPost)表服务实现类
 *
 * @author makejava
 * @since 2022-11-23 09:20:10
 */
@Service("jobWorkShopPostService")
public class JobWorkShopPostServiceImpl implements JobWorkShopPostService {
    @Resource
    private JobWorkShopPostMapper jobWorkShopPostDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public JobWorkShopPost queryById(Integer id) {
        return this.jobWorkShopPostDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param jobWorkShopPost 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<JobWorkShopPost> queryByPage(JobWorkShopPost jobWorkShopPost, PageRequest pageRequest) {
        long total = this.jobWorkShopPostDao.count(jobWorkShopPost);
        return new PageImpl<>(this.jobWorkShopPostDao.queryAllByLimit(jobWorkShopPost, pageRequest), pageRequest, total);
    }

    @Override
    public List<JobWorkShopPost> queryAll(JobWorkShopPost jobWorkShopPost) {
        return jobWorkShopPostDao.queryAll(jobWorkShopPost);
    }

    /**
     * 新增数据
     *
     * @param jobWorkShopPost 实例对象
     * @return 实例对象
     */
    @Override
    public JobWorkShopPost insert(JobWorkShopPost jobWorkShopPost) {
        this.jobWorkShopPostDao.insert(jobWorkShopPost);
        return jobWorkShopPost;
    }

    /**
     * 修改数据
     *
     * @param jobWorkShopPost 实例对象
     * @return 实例对象
     */
    @Override
    public JobWorkShopPost update(JobWorkShopPost jobWorkShopPost) {
        this.jobWorkShopPostDao.update(jobWorkShopPost);
        return this.queryById(jobWorkShopPost.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.jobWorkShopPostDao.deleteById(id) > 0;
    }
}
